﻿using System.Collections.Generic;
using NUnit.Framework;
using HighDiveEngine.IoEngines;

namespace UnitTestHighDive
{
    [TestFixture]
    public class UnitTestXmlHandler
    {
        public Dictionary<string, double> OriginalDictionary = new Dictionary<string, double>();
        public Dictionary<string, double> LoadedDictionary;

        [SetUp]
        public void SetupFunc()
        {
           if(System.IO.File.Exists("dicttest.xml"))
               System.IO.File.Delete("dicttest.xml");
            OriginalDictionary.Clear();
            OriginalDictionary.Add("11", 1.1);
            OriginalDictionary.Add("22", 2.2);
            OriginalDictionary.Add("33", 3.3);
            OriginalDictionary.Add("44", 4.4);
            OriginalDictionary.Add("55", 5.5);
            LoadedDictionary = null;
        }

        [Test]
        public void TestSaveDict()
        {
            XmlEngine.SaveDictionary(OriginalDictionary, "dicttest");
            Assert.IsTrue(System.IO.File.Exists("dicttest.xml"));
        }

        [Test]
        public void TestLoadDict()
        {
            XmlEngine.SaveDictionary(OriginalDictionary, "dicttest");
            LoadedDictionary = XmlEngine.LoadDictionary("dicttest");
            foreach (var item in OriginalDictionary)
            {
                Assert.AreEqual(OriginalDictionary[item.Key], LoadedDictionary[item.Key]);
            }
        }
    }
}
